package com.example.service.impl;

import com.example.entity.Role;
import com.example.entity.example.RoleExample;
import com.example.mapper.RoleMapper;
import com.example.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {
    @Autowired(required = false)
    RoleMapper roleMapper;

    @Override
    public List<Role> getByExampleWithLimit(RoleExample example, Integer curPage, Integer pageSize) {
        int begin = (curPage - 1) * pageSize;
        return roleMapper.selectByExampleWithLimit(example, begin, pageSize);
    }

    @Override
    public long getCountByExample(RoleExample example) {
        return roleMapper.countByExample(example);
    }

    @Override
    public void addRole(Role role) {
        roleMapper.insert(role);
    }

    @Override
    public String getNameById(Integer roleId) {
        return roleMapper.selectByPrimaryKey(roleId).getRname();
    }

    @Override
    public void removeById(Integer id) {
        roleMapper.deleteByPrimaryKey(id);
    }

    @Override
    public void updateById(Role role) {
        roleMapper.updateByPrimaryKey(role);
    }
}
